<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<TITLE>Kalamazoo Animal Rescue - Add a Pet to Event Calendar</TITLE>

<script language="JavaScript">

<!-- Begin

//   This JS just checks to make sure something is entered in all fields.
function verifyEntry() {

	// check to make sure all "nones" aren't still selected
	// Notice we're checking the index and not the .value
	var pet_1 = document.f.pet_1.selectedIndex
	var pet_2 = document.f.pet_2.selectedIndex
	var pet_3 = document.f.pet_3.selectedIndex
	var event = document.f.event.selectedIndex

	if (event == 0) {
		alert("You must select an event.")
		return false
		}

	if ((pet_1 == 0) && (pet_2 == 0) && (pet_3 == 0))  {
		alert("You must select at least one pet to add.")
		return false
		}

	// check to make sure that the same pet isn't selected twice
//	alert (pet_1 + " " + pet_2 + " "+ pet_3)
	if (pet_1 == 0) {
		pet_1 = 'one'		// just to make it different than 0
		}
	if (pet_2 == 0) {
		pet_2 = 'two'		// just to make it different than 0
		}

	if (pet_1==pet_2 || pet_1==pet_3 || pet_2==pet_3) {
		alert("Don't select the same pet more than once!")
		return false
		}

	arrive_hour =  parseInt(document.f.a_hour[document.f.a_hour.selectedIndex].value)
	arrive_min =     parseInt(document.f.a_minute[document.f.a_minute.selectedIndex].value)
	depart_hour = parseInt(document.f.d_hour[document.f.d_hour.selectedIndex].value)
	depart_min =   parseInt(document.f.d_minute[document.f.d_minute.selectedIndex].value)

	var arrival_mode = document.f.a_ampm.value
	var depart_mode = document.f.d_ampm.value

	if ((arrival_mode == 'pm') && (arrive_hour != 12))
		{ arrive_hour += 12
		}
	if ((depart_mode == 'pm') && (depart_hour != 12))
		{ depart_hour += 12
		}
//	alert (arrive_hour + " is arrive_hour and " + depart_hour + " is depart_hour")
		
	var arrival_time = arrive_hour*100 + arrive_min	// so we get 1600 + 45, for instance which was 4:45pm
	var depart_time = depart_hour*100 + depart_min

	if (arrival_time >= depart_time)
		{
		alert("Check your arrive and depart time.  They don't make sense \nunless you are leaving the pet(s) overnight.")
		return false
		}

	return true

}


//  End Hide -->

</script>

<?php 
include($_SERVER['DOCUMENT_ROOT'] ."/includes/db.php");				// Connect to the database server
dbConnect('kar_web1');   	// Use function in db.php to connect

$today= date("Y-m-d");	  // this will be put in a hidden form field to be used in JS to validate the date

// Get set up to put foster home/pet  names  into drop-down list for SELECT in Form
//  This is to present the user a drop down of possible Pets/Foster Homes
$result = @mysql_query("SELECT * FROM cats, dogs, volunteers
			     WHERE (cats.pet_status='v' OR dogs.pet_status='v') AND
			     (cats.volunteer_id = volunteers.volunteer_id OR
			     dogs.volunteer_id = volunteers.volunteer_id)
			    ORDER BY display_name");
if (!$result) {
  echo("<p>Error performing query: " . mysql_error() . "</p>");
  exit();
  }  // end if

//   Loop through and write long Option_Block string containing database data
$option_block = "<OPTION value=\"NULL\" SELECTED>none</OPTION>";
while ($row = mysql_fetch_array($result)) {
	$pet_id = $row["tagNum"];
	$name  = $row["display_name"];
	$pet = $row["pet_name"];
	$option_block .= "<OPTION value=\"$pet_id\">$pet - $name</OPTION>";
}  // end while



// Get set up to put events  into drop-down list for SELECT in Form
//  This is to present the user a drop down of possible events to schedule for
//  Only displays events that have not passed.
$resultEvent = @mysql_query("SELECT * FROM events 
			     WHERE eventDate > CURDATE() OR (eventDate = CURDATE() AND eventEndTime > CURTIME())
				ORDER BY eventDate");
if (!$resultEvent) {
  echo("<p>Error performing query: " . mysql_error() . "</p>");
  exit();
  }  // end if

//   Loop through and write long Option_Block string containing database data
$option_blockEvent = "<OPTION value=\"NULL\" SELECTED>none</OPTION>";
$eventList = "";
while ($row = mysql_fetch_array($resultEvent)) {
	$eventLoc = $row['location_id'];
    $query = "SELECT * FROM locations WHERE location_id = ".$eventLoc;
    $locationInfo = mysql_fetch_array(@mysql_query($query));
	if($row["eventName"] != '')
		$eventName = $row["eventName"];
	else
    	$eventName = $locationInfo["name"]." on ".$locationInfo["address"];
// Setting up BeginTime & EndTime to print in Tips section 
	$BTime =  $row["eventBeginTime"];
	list($Bhour, $Bmin, $Bsec) = explode(":", $BTime);
	$BeginTime = date("g:i a", mktime($Bhour, $Bmin));
	$ETime =  $row["eventEndTime"];
	list($Ehour, $Emin, $Esec) = explode(":", $ETime);
	$EndTime = date("g:i a", mktime($Ehour, $Emin));

// eventID is the primary key for the Events Table and will be stored with the scheduled  pet record
	$event = $row["eventID"];
//  eventDate is stored in format yyyy-mm-dd
	list($year, $month, $day)  = explode("-", $row["eventDate"]);
	$eventDate = date("l, F j", mktime(0,0,0,$month, $day,$year));
// SAMPLE OF USAGE $showdate = date("l, F j, Y", mktime(0,0,0,$month, $day,$year));
	$option_blockEvent .= "<OPTION value=\"$event\">$eventName - $eventDate</OPTION>";
	$eventList .= $eventName ." on ". $eventDate." from ". $BeginTime . " to " . $EndTime . "<BR>";
}  // end while

	
?>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#800000">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


<?php include($_SERVER['DOCUMENT_ROOT'] ."/includes/head.inc");  ?>



<style type="text/css">

<!--
.tcell { font-size: 10pt; }

.style5 {color: #FF0000}
.style8 {color: #999999; }
.style15 {color: #000000; }
.style20 {font-size: 14px; color: #000000; }
.style22 {font-size: 14px}
.style24 {
	color: #FF0000;
	font-size: 1.2em;
}
.style27 {font-weight: bold}
.style29 {color: #000000; font-weight: bold; }
.style30 {color: #0000CC}
.style31 {color: #FF003A}
.style33 {
	font-size: 24pt;
	font-family: "Courier New", Courier, monospace;
}

-->

</style>
</head>

<body>

<!--initial body width and height set up  -->

<div id="bodywidth"><!--begin body of page-->

<?php include($_SERVER['DOCUMENT_ROOT'] ."/includes/header.inc");  ?>
<?php include($_SERVER['DOCUMENT_ROOT'] ."/includes/leftmenu.inc");  ?>

<div id="wide2column"><!--begin body of page-->

<h2>Kalamazoo Animal Rescue Event Calendar </h2>


<blockquote>
<table><tr><td valign="top">

<form name="f" action="sched_it2.php" method="POST" onSubmit="return verifyEntry()">
<table cellpadding=0 cellspacing=0 border=0 bgcolor="#000000"><tr><td>
<table cellpadding=4 cellspacing=1 border=0 bgcolor="#FFFFFF">
<tr><td colspan=2 bgcolor="#000000"><font size="+1" color="#FFFFFF"><b>Add Foster Animal to Event Schedule</b></font></td></tr>
<tr><td><b>Pet #1:</b></td><td>

<INPUT TYPE="HIDDEN" NAME="today" VALUE="<?php echo($today);?>">

<SELECT  name="pet_1">
<? echo "$option_block"; ?>
</SELECT><BR>
</td></tr>
<tr><td><b>Pet #2:</b></td><td>
<SELECT  name="pet_2">
<? echo "$option_block"; ?>
</SELECT><BR>
</td></tr>

<tr><td><b>Pet #3:</b></td><td>
<SELECT  name="pet_3">
<? echo "$option_block"; ?>
</SELECT><BR>
</td></tr>

<tr><td><b>Event</b></td><td>
<SELECT  name="event">
<? echo "$option_blockEvent"; ?>
</SELECT><BR>
</td></tr>

<tr><td><b>Arrive Time:</b></td><td>
<select NAME="a_hour">

    <option VALUE="1">1
    <option VALUE="2">2
    <option VALUE="3">3
    <option VALUE="4">4
    <option VALUE="5">5
    <option VALUE="6">6
    <option VALUE="7">7
    <option VALUE="8">8
    <option VALUE="9">9
    <option VALUE="10">10
    <option VALUE="11">11
    <option VALUE="12" SELECTED>12
    </select>
:    <select NAME="a_minute">
    <option VALUE="00" SELECTED>00
    <option VALUE="15">15
    <option VALUE="30">30
    <option VALUE="45">45
    </select>
    <select NAME="a_ampm">
    <option VALUE="am">a.m.
    <option VALUE="pm" SELECTED>p.m.
  </select>
</td>
</tr> 
<tr><td><b>Depart Time:</b></td><td><select NAME="d_hour">
    <option VALUE="1">1
    <option VALUE="2">2
    <option VALUE="3">3
    <option VALUE="4">4
    <option VALUE="5">5
    <option VALUE="6">6
    <option VALUE="7">7
    <option VALUE="8">8
    <option VALUE="9">9
    <option VALUE="10">10
    <option VALUE="11">11
    <option VALUE="12" SELECTED>12
    </select>
:    <select NAME="d_minute">
    <option VALUE="00" SELECTED>00
    <option VALUE="15">15
    <option VALUE="30">30
    <option VALUE="45">45
    </select>
    <select NAME="d_ampm">
    <option VALUE="am">a.m.
    <option VALUE="pm" SELECTED>p.m.
  </select>
</td></tr> 

<tr><td colspan=2 align="center" bgcolor="#CCCCCC"><input type=submit value="Add to Schedule"><input type=reset value="Reset"></td></tr>
</table></td></tr></table></form>

</td><td width=25 nowrap><br></td>
<td valign="top">

</td></tr></table>

</blockquote>




<BR><BR><BR><HR width="75%">
<div  align=center>
<B>Tips for Completing this Form</B>
</div>
<OL> 
<LI>Today is

<?php
    list($Curyear, $Curmonth, $Curday) = explode("-", $today); 
    $showMonth = date("l, F j, Y", mktime(0,0,0,$Curmonth, $Curday,$Curyear));
    echo ($showMonth . "<BR><BR>");
?>

<LI>Upcoming Events are:<BR>
<UL>
<B><I>
<?php echo $eventList ?>
</I></B>
</UL>
<BR>
<LI>Select the pet(s)  from the pulldown(s).  If you need to schedule more than 3 pets, hit your browser's BACK button after submitting the first set of pets.<BR><BR>


<LI>Select the hour, minute & am/pm for both arrival and departure times.<BR><BR>

<LI>Click the "Add to Schedule" button when you have made your entries.<BR><BR>

<LI><font size="+1" color=red><u>You are responsible for checking the Event List above for appropriate times.</u></font> This form will not stop you if you schedule your pets for times that do not make sense.<BR><BR>

<LI>If you try to submit a pet(s) that is already on the schedule for that day, you will receive a message telling you that you can't do that after you hit the "Add to Schedule" button.  Any other pets that weren't already on the schedule that you had selected to add will be added.
</OL>
<BR>
Return to <a href="sched_admin.php">Scheduler Admin Page</a>

</div>

<?php include($_SERVER['DOCUMENT_ROOT'] ."/includes/footer.inc");  ?>

<!--tag below ends bodywidth div -->

</div>

</body>

</html>

